﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using Datalayer;
using Common;
using System.Data;

namespace Portal_KonTum.Admin
{
    public partial class ConfigureWeb : System.Web.UI.Page
    {
        IQueryMgr iq;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                iq = QueryMgr.GetDbInstance();
                bin_edit();
                bt_save.Text = "Save";
            }
        }

        protected void bt_save_Click(object sender, EventArgs e)
        {
            try
            {
                iq = QueryMgr.GetDbInstance();
                // sua doi
                Guid gd = MethodCommon.Get_Guid("7781b941-248b-4f4a-b405-a4ca25af767f");
                iq.wcf_EditCategory(set_Wcf(gd));

                lb_note.CssClass = "notification n-sucess";
                lb_note.Visible = true;
                lb_note.Text = "Thay đổi thông tin thành công";
            }
            catch (Exception ex)
            {
                lb_note.CssClass = "notification n-error";
                lb_note.Visible = true;
                lb_note.Text = "Lỗi :" + ex.ToString();
            }
        }

        protected void bt_cancel_Click(object sender, EventArgs e)
        {

        }

        void Fill_DataEdit(WebConfig bg)
        {
            txt_title.Text = bg.WebTitle;
            txt_notes.Text = bg.WebNotes;
            CKEditor1.Text = bg.WebFooter;
        }

        void bin_edit()
        {
            WebConfig bg = new WebConfig();
            iq = QueryMgr.GetDbInstance();
            bg = iq.wcf_GetWebconfByID();
            Fill_DataEdit(bg);
        }

        /// <summary>
        /// Sửa chữa bug
        /// </summary>
        /// <param name="bg"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        WebConfig set_Wcf(Guid id)
        {
            WebConfig bg = new WebConfig();

            if (id != null) //sửa chữa
                bg.ConfigID = id;

            bg.WebFooter = CKEditor1.Text;
            bg.WebNotes = txt_notes.Text;
            bg.WebTitle = txt_title.Text;
            return bg;
        }
    }
}